home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-08-03 | 6.0 KB | 224 lines | [TEXT/KAHL] |
- /******************************************************************************
- CResBrowser.c
-
- A subclass of CDirector that manages a window containing a list
- of resources.
-
- SUPERCLASS = CDirector
-
- Copyright © 1991 Symantec Corporation. All rights reserved.
-
- TCL 1.1.3 Changes
- [
- - CResBrowser::MakeResourceWindow must return a CDirector * value, in this
- case, 0.
- ]
- ******************************************************************************/
-
- #include "CResBrowser.h"
- #include "CResListPane.h"
- #include "CBrowseResDoc.h"
- #include "TBUtilities.h"
- #include "CDesktop.h"
- #include "CScrollPane.h"
- #include "CDecorator.h"
- #include "CWindow.h"
- #include "CArray.h"
-
- #define kResBrowseWind 1025 // 'WIND' resource ID
- #define cmdOpenType 1050 // open window on a resource type
- #define cmdOpenResource 1051 // open window on a resource
-
- extern CDesktop *gDesktop;
- extern CDecorator *gDecorator;
-
- /******************************************************************************
- IResBrowser
-
- Initialize CResBrowser. Creates a window to display the given list of
- resources of the given type.
-
- ******************************************************************************/
-
- void CResBrowser::IResBrowser( CBrowseResDoc *aSupervisor, ResType aResType,
- CArray *aResList)
- {
- Str255 title;
- Str31 suffix;
-
- resType = aResType;
- itsResList = aResList;
- itsResPane = NULL;
-
- CDirector::IDirector( aSupervisor);
-
- // set the title of the window to Filename - ResType,
- // e.g. "Sample - DLOG"
-
- aSupervisor->GetName( title);
- ConcatPStrings( title, "\p - xxxx");
- BlockMove( &aResType, &title[ Length(title) - 3], sizeof(ResType));
-
- // create the window
-
- BuildWindow();
-
- // Set the window title
-
- itsWindow->SetTitle( title);
-
- // Position the window on screen and show it.
-
- gDecorator->StaggerWindow( itsWindow);
- itsWindow->Select();
- }
-
- /******************************************************************************
- Dispose
-
- Dispose of the resource list when the window is closed.
-
- ******************************************************************************/
-
- void CResBrowser::Dispose( void)
- {
- ForgetObject( itsResList);
- inherited::Dispose();
- }
-
- /******************************************************************************
- DoCommand
-
- Respond to the cmdOpenResource command. It is sent when the user
- double clicks on a resource name/ID.
-
- ******************************************************************************/
-
- void CResBrowser::DoCommand( long aCommand)
- {
- tResourceInfo resInfo;
- Cell selectedCell;
-
- switch( aCommand)
- {
- case cmdOpenResource:
-
- // determine the selected cell.
-
- selectedCell.h = selectedCell.v = 0;
- if (itsResPane->GetSelect( kCurrentOrNext, &selectedCell))
- {
-
- // get the resource info for the selected cell
- // if it alreadt has a window, just show it,
- // otherwise create a new window for the resource
-
- itsResList->GetItem( &resInfo, selectedCell.v+1);
- if (resInfo.window)
- resInfo.window->GetWindow()->Select();
- else
- {
-
- resInfo.window = MakeResourceWindow( &resInfo);
- itsResList->SetItem( &resInfo, selectedCell.v + 1);
- }
- }
- break;
-
- default:
- inherited::DoCommand( aCommand);
- break;
- }
- }
-
- /******************************************************************************
- BuildWindow
-
- Creates the window for display the resource list. CResListPane is a
- subclass of CArrayPane that displays the scrolling list of resources.
-
- ******************************************************************************/
-
- void CResBrowser::BuildWindow( void)
- {
- CScrollPane *scrollPane;
-
- // First, create a window.
-
- itsWindow = new CWindow;
- itsWindow->IWindow( kResBrowseWind, kNotFloating, gDesktop, this);
-
- // Next, add a scroll pane with a vertical scroll bar and
- // a size box.
-
- scrollPane = new CScrollPane;
- scrollPane->IScrollPane( itsWindow, this, 0, 0, 0, 0,
- sizELASTIC, sizELASTIC, kNoHScroll, kHasVScroll, kHasSizebox);
- scrollPane->FitToEnclFrame( kDoHorizontal, kDoVertical);
-
- // Next, add the CResListPane
-
- itsResPane = new CResListPane;
- itsResPane->IResListPane( scrollPane, this, 0, 0, 0, 0,
- sizELASTIC, sizELASTIC);
- itsResPane->FitToEnclosure( kDoHorizontal, kDoVertical);
-
- // Install the resource list into the CResListPane,
- // and set the double click command and selection flags
-
- itsResPane->SetArray( itsResList, FALSE);
- itsResPane->SetDblClickCmd( cmdOpenResource);
- itsResPane->SetSelectionFlags( selOnlyOne);
-
- // Connect the panorama to the scroll pane.
-
- scrollPane->InstallPanorama( itsResPane);
-
- itsGopher = itsResPane;
- }
-
- /******************************************************************************
- MakeResourceWindow
-
- Called when the user double clicks on a resource in the list. Subclasses
- must override to display a particular resource type. CDLOGBrowser
- overrides this method to display a DLOG window. This method just beeps.
- ******************************************************************************/
-
- CDirector *CResBrowser::MakeResourceWindow( tResourceInfo *aResource)
- {
- SysBeep( 3);
- return 0;
- }
-
- /******************************************************************************
- RemoveDirector {OVERRIDE}
-
- RemoveDirector is called when a subordinate director is being closed.
- Since we store a reference to the subordinate director associated with
- a resource in itsResList, we must be sure to clear that reference when
- the subordinate director is closed.
- ******************************************************************************/
-
- static int FindResDirector( CDirector *resDirector, tResourceInfo *resInfo)
- {
- if (resInfo->window == resDirector)
- {
- resInfo->window = NULL;
- return 0;
- }
- return 1;
- }
-
- void CResBrowser::RemoveDirector( CDirector *aDirector)
- {
- // Search the resource list to find the reference to
- // this director. The search routine clears the
- // reference as soon as it is found.
-
- if (itsResList)
- itsResList->Search( aDirector, (CompareFunc) FindResDirector);
-
- inherited::RemoveDirector( aDirector);
- }
-